﻿// Preset.cs (c) Copyright 2009, Mike Hodnick : www.hodnick.com

using System.Collections.Generic;
using System.Windows;
using Kindohm.KSynth.Library;
using System;

namespace Kindohm.KSynth.AudioCanvas
{
    public abstract class Preset
    {
        public bool Muted { get; protected set; }
        public bool PulseEnabled { get; protected set; }
        public int PulseBpm { get; protected set; }
        public string Name { get; protected set; }

        public abstract Dictionary<Oscillator, OscillatorPresetInfo> Create();
    }

    public class OscillatorPresetInfo
    {
        public Point Location { get; set; }
        public bool FrequencyModulatorExpanded { get; set; }
        public bool AmplitudeModulatorExpanded { get; set; }
        public bool FrequencyModulatorEnvelopeExpanded { get; set; }
        public bool AmplitudeModulatorEnvelopeExpanded { get; set; }
        public bool EnvelopeExpanded { get; set; }
    }

    public class BassDronePreset : Preset
    {
        public BassDronePreset()
        {
            this.Name = "Bass Drone";
        }

        public override Dictionary<Oscillator, OscillatorPresetInfo> Create()
        {
            Oscillator mainLeft = Oscillator.Create(100);
            mainLeft
                .Pan(short.MinValue)
                .Attenuate(-10);
            mainLeft.FrequencyModulate(41, 1210000, WaveForm.Square);

            Oscillator mainRight = Oscillator.Create(102);
            mainRight
                .Pan(short.MaxValue)
                .Attenuate(-10);
            mainRight.FrequencyModulate(42, 1300000, WaveForm.Square);

            Oscillator sub = Oscillator.Create(50);
            sub.Pan(0).Attenuate(-10);
            sub.FrequencyModulate(30, 100000, WaveForm.Square);
            sub.AmplitudeModulate(0.10d);

            Oscillator fuzzLeft = Oscillator.Create(50.5, WaveForm.Square);
            fuzzLeft.Pan(short.MinValue).Attenuate(-40);
            Oscillator fuzzRight = Oscillator.Create(51, WaveForm.Square);
            fuzzRight.Pan(short.MaxValue).Attenuate(-40);

            Dictionary<Oscillator, OscillatorPresetInfo> items = new Dictionary<Oscillator, OscillatorPresetInfo>();
            items.Add(mainLeft, new OscillatorPresetInfo()
            {
                FrequencyModulatorExpanded = true,
                Location = new Point() { X = 3600, Y = 3700 }
            });
            items.Add(sub, new OscillatorPresetInfo()
            {
                AmplitudeModulatorExpanded = true,
                FrequencyModulatorExpanded = true,
                Location = new Point() { X = 3900, Y = 3800 }
            });

            items.Add(mainRight, new OscillatorPresetInfo()
            {
                FrequencyModulatorExpanded = true,
                Location = new Point() { X = 4200, Y = 3700 }
            });

            items.Add(fuzzLeft, new OscillatorPresetInfo()
            {
                Location = new Point() { X = 4400, Y = 3700 }
            });

            items.Add(fuzzRight, new OscillatorPresetInfo()
            {
                Location = new Point() { X = 4600, Y = 3700 }
            });

            return items;
        }
    }

    public class SomeOtherPreset : Preset
    {
        public SomeOtherPreset()
        {
            this.Name = "Phone Drone";
            this.PulseBpm = 168;
            this.PulseEnabled = true;
        }

        public override Dictionary<Oscillator, OscillatorPresetInfo> Create()
        {
            Oscillator mainLeft = Oscillator.Create(1000);
            mainLeft
                .Pan(short.MinValue)
                .Attenuate(-13);
            mainLeft.FrequencyModulate(8, 9300000, WaveForm.Square);
            mainLeft.FrequencyModulator.Envelope.Attack = 0;
            mainLeft.FrequencyModulator.Envelope.Sustain = 5000;
            mainLeft.FrequencyModulator.Envelope.Release = 5000;


            Oscillator mainRight = Oscillator.Create(800);
            mainRight
                .Pan(short.MaxValue)
                .Attenuate(-13);
            mainRight.FrequencyModulate(9.5, 9300000, WaveForm.Square);
            mainRight.FrequencyModulator.Envelope.Attack = 0;
            mainRight.FrequencyModulator.Envelope.Sustain = 9000;
            mainRight.FrequencyModulator.Envelope.Release = 5000;

            Oscillator secondLeft = Oscillator.Create(400);
            secondLeft.Pan(short.MinValue).Attenuate(-10);
            secondLeft.AmplitudeModulate(61);
            secondLeft.AmplitudeModulator.Envelope.Attack = 0;
            secondLeft.AmplitudeModulator.Envelope.Sustain = 100000;
            secondLeft.AmplitudeModulator.Envelope.Release = 0;

            Oscillator secondRight = Oscillator.Create(402);
            secondRight.Pan(short.MaxValue).Attenuate(-10);
            secondRight.AmplitudeModulate(53);
            secondRight.AmplitudeModulator.Envelope.Attack = 0;
            secondRight.AmplitudeModulator.Envelope.Sustain = 100000;
            secondRight.AmplitudeModulator.Envelope.Release = 0;

            Oscillator bass = Oscillator.Create(100);
            bass.Pan(0).Attenuate(-15);
            bass.AmplitudeModulate(40);
            bass.AmplitudeModulator.Envelope.Attack = 0;
            bass.AmplitudeModulator.Envelope.Sustain = 1000000;
            bass.AmplitudeModulator.Envelope.Release = 0;

            Dictionary<Oscillator, OscillatorPresetInfo> items = new Dictionary<Oscillator, OscillatorPresetInfo>();
            items.Add(mainLeft,
                new OscillatorPresetInfo()
            {
                FrequencyModulatorExpanded = true,
                FrequencyModulatorEnvelopeExpanded = true,
                Location = new Point() { X = 3470, Y = 3740 }
            });
            items.Add(mainRight,
                new OscillatorPresetInfo()
                {
                    FrequencyModulatorEnvelopeExpanded = true,
                    FrequencyModulatorExpanded = true,
                    Location = new Point() { X = 3600, Y = 3890 }
                });
            items.Add(secondLeft,
                new OscillatorPresetInfo()
                {
                    AmplitudeModulatorExpanded = true,
                    AmplitudeModulatorEnvelopeExpanded = true,
                    Location = new Point() { X = 4000, Y = 4040 }
                });

            items.Add(secondRight,
                new OscillatorPresetInfo()
                {
                    AmplitudeModulatorExpanded = true,
                    AmplitudeModulatorEnvelopeExpanded = true,
                    Location = new Point() { X = 4250, Y = 3940 }
                });

            items.Add(bass,
                new OscillatorPresetInfo()
                {
                    AmplitudeModulatorExpanded = true,
                    AmplitudeModulatorEnvelopeExpanded = true,
                    Location = new Point() { X = 4400, Y = 3740 }
                });

            return items;
        }
    }
}
